# 添加日志管理菜单到数据库的脚本
# 这个脚本将为现有数据库添加日志管理菜单和权限配置

Write-Host "正在添加日志管理菜单到数据库..." -ForegroundColor Green

# 数据库连接字符串（请根据实际情况修改）
$connectionString = "Host=localhost;Database=groupsix;Username=postgres;Password=123456"

# SQL脚本
$sqlScript = @"
-- 添加日志管理菜单
INSERT INTO gs_menus (
    "Id", 
    "Menuname", 
    "MenuPath", 
    "MenuIcon", 
    "ParentId", 
    "Order", 
    "PermissionKey", 
    "IsActive", 
    "IsDeleted", 
    "CreatedAt", 
    "UpdatedAt", 
    "CreatedBy", 
    "UpdatedBy"
) VALUES (
    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
    '日志管理',
    '/system/logs',
    'FileTextOutlined',
    '77777777-7777-7777-7777-777777777777',
    4,
    'operationlog',
    true,
    false,
    NOW(),
    NOW(),
    '00000000-0000-0000-0000-000000000000',
    '00000000-0000-0000-0000-000000000000'
) ON CONFLICT ("Id") DO NOTHING;

-- 为超级管理员添加日志管理权限
INSERT INTO gs_role_menus (
    "Id",
    "RoleId",
    "MenuId",
    "IsActive",
    "IsDeleted",
    "CreatedAt",
    "UpdatedAt",
    "CreatedBy",
    "UpdatedBy"
) VALUES (
    '11111111-1111-1111-1111-111111111112',
    '11111111-1111-1111-1111-111111111111',
    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
    true,
    false,
    NOW(),
    NOW(),
    '00000000-0000-0000-0000-000000000000',
    '00000000-0000-0000-0000-000000000000'
) ON CONFLICT ("Id") DO NOTHING;

-- 为管理员添加日志管理权限
INSERT INTO gs_role_menus (
    "Id",
    "RoleId",
    "MenuId",
    "IsActive",
    "IsDeleted",
    "CreatedAt",
    "UpdatedAt",
    "CreatedBy",
    "UpdatedBy"
) VALUES (
    '22222222-2222-2222-2222-222222222225',
    '22222222-2222-2222-2222-222222222222',
    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
    true,
    false,
    NOW(),
    NOW(),
    '00000000-0000-0000-0000-000000000000',
    '00000000-0000-0000-0000-000000000000'
) ON CONFLICT ("Id") DO NOTHING;
"@

try {
    # 使用psql执行SQL脚本
    $sqlScript | psql -d $connectionString
    
    Write-Host "日志管理菜单添加成功！" -ForegroundColor Green
    Write-Host "现在超级管理员和管理员都可以访问日志管理功能了。" -ForegroundColor Yellow
    
} catch {
    Write-Host "执行SQL脚本时出错: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "请确保PostgreSQL已安装并且psql命令可用。" -ForegroundColor Yellow
    Write-Host "或者您可以手动执行以下SQL脚本:" -ForegroundColor Yellow
    Write-Host $sqlScript -ForegroundColor Cyan
} 